<?
function sendmail()
{
	  $conn=getconnection();
    $sql = "select * from mails where forward is not null and (forwardpos is null or forwardpos<forwardcount) and forwardcount>0";
    $result=mysql_query($sql,$conn);
    $mailcount=0;
    while ($row=mysql_fetch_array($result) and $mailcount++<1)
    {
        $pos = $row['forwardpos'];
        if ($pos=="")
        {
            $pos=0;
        }
        $pieces = explode(",", $row['forward']);
        $memberid=$pieces[$pos];
        if ($memberid!="")
        {
            //sendmail
            $sqluser = "select * from member where id=".$memberid;
            $resultuser=mysql_query($sqluser,$conn);
            if($rowuser=mysql_fetch_array($resultuser))
            {
            	 /*
            	  $body=htmlspecialchars_decode(stripslashes($row['body']));
            	  echo "----------------------------------1----------------------------<br>\r\n";
            	  echo $row['body'];
            	  echo "-----------------------------------a---------------------------<br>\r\n";
            	  echo stripslashes($row['body']);
            	  echo "-------------------------------------b-------------------------<br>\r\n";
            	  echo htmlspecialchars_decode(stripslashes($row['body']));
            	  echo "-----------------------------------c---------------------------<br>\r\n";
            	  echo htmlspecialchars_decode($row['body']);
            	  echo "-------------------------------------d-------------------------<br>\r\n";
            	  echo stripslashes(htmlspecialchars_decode($row['body']));
            	  */
                sendmailout($rowuser['email'],$row['subject'],htmlspecialchars_decode(stripslashes($row['body'])));
                $sqlupdate = "update mails set forwardpos=".($pos+1).",senddate=CURDATE() where id=".$row['id'];
                $resultabc=mysql_query($sqlupdate,$conn);
            }
        }
    }
    mysql_close($conn);
}
function sendmailout($email,$subject,$body)
{
    $mail = new PHPMailer();

    $mail->IsSMTP();                       // send via SMTP
    $mail->Host     = "mail.uwannamail.com"; // SMTP servers
    $mail->Port = 26; // SMTP port
    $mail->SMTPAuth = true;     // turn on SMTP authentication
    $mail->Username = "admin@uwannamail.com";  // SMTP username
    $mail->Password = "ByronStraat9"; // SMTP password

    $mail->From     = "admin@uwannamail.com";
    $mail->FromName = "admin";
    $mail->AddAddress($email);
    $mail->AddReplyTo("admin@uwannamail.com","Uwannamail Admin");

    $mail->WordWrap = 50;                              // set word wrap
    //$mail->AddAttachment("/var/tmp/file.tar.gz");      // attachment
    //$mail->AddAttachment("/tmp/image.jpg", "new.jpg");
    $mail->IsHTML(false);                               // send as HTML

    $mail->Subject  =  $subject;
    $mail->Body     =  $body;
    //$mail->AltBody  =  "This is the text-only body";

    if(!$mail->Send())
    {
        //echo "Message was not sent <p>";
       // echo "Mailer Error: " . $mail->ErrorInfo;
        //exit;
    }
}
?>